package jevon.philautus.domain;

import java.util.ArrayList;
import java.util.List;

/**
 * 分页
 * 
 * @author lyj
 * 
 */
public class Pager<T> {
	private int pageSize = 15;
	private int totalPages;
	private int currentPage = 1;
	private boolean hasPrev = false;
	private boolean hasNext = false;
	private List<T> list = new ArrayList<T>();

	public Pager() {

	}

	public Pager(int page, int size, int totalPages, List<T> list) {
		this.currentPage = page;
		this.pageSize = size;
		this.totalPages = totalPages;
		this.hasPrev = this.currentPage != 1;
		this.hasNext = this.totalPages > this.currentPage;
		this.list = list;
		if (this.list == null || this.list.size() == 0) {
			this.currentPage = 1;
			this.totalPages = 1;
			this.hasNext = false;
			this.hasPrev = false;
		}
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getTotalPages() {
		return totalPages;
	}

	public void setTotalPages(int totalPages) {
		this.totalPages = totalPages;
		this.hasNext = this.totalPages > this.currentPage;
	}

	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
		this.hasPrev = this.currentPage != 1;
	}

	public boolean isHasPrev() {
		return hasPrev;
	}

	public void setHasPrev(boolean hasPrev) {
		this.hasPrev = hasPrev;
	}

	public boolean isHasNext() {
		return hasNext;
	}

	public void setHasNext(boolean hasNext) {
		this.hasNext = hasNext;
	}

	public List<T> getList() {
		return list;
	}

	public void setList(List<T> list) {
		this.list = list;
		if (this.list == null || this.list.size() == 0) {
			this.currentPage = 1;
			this.totalPages = 1;
			this.hasNext = false;
			this.hasPrev = false;
		}
	}

}
